'''
Author: linxuan
Date: 2022-07-10 08:54:49
Description: file content
FilePath: /stealer/src/opensea_combine.py
'''
import pandas as pd
import glob
import re

allfiles = glob.glob('/resources/result_to*.csv'[1:])
# 由于name属性里可能有,因此需要用正则处理一下
all_lines = []
for file in allfiles:
    with open(file, 'r') as f:
        lines = f.readlines()
    if all_lines == []:
        all_lines.append(lines[0])
    for line in lines[1:]:
        if len(line.split(',')) > len(lines[0].split(',')):
            k = len(line.split(',')) - len(lines[0].split(','))
            new_line = '"' + ''.join(line.split(',')[:k+1]) + '"' + ',' + ','.join(line.split(',')[k+1:])
            all_lines.append(new_line)
        else:
            all_lines.append(line)
with open('/resources/opensea_result.csv'[1:], 'w') as f:
    f.writelines(all_lines)
